<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<button id="closeWnd">Close window</button>
<script>
    var closeWndBtn = document.getElementById('closeWnd');

    closeWndBtn.addEventListener('click', function () {
        window.opener.postMessage('message', '*');
        window.setTimeout(function () {
            window.close();
        }, 10);
    });
</script>
</body>
</html>
